package com.easy;

/**
 * Created by Lxk on 2019/11/3.
 */
public class Solution704 {

    public int search(int[] nums, int target) {
        int high = nums.length - 1, low = 0;
        int mid = 0;
        while (low <= high) {
            mid = ((high - low) / 2) + low;
            if (nums[mid] > target) {
                high = mid - 1;
            } else if (nums[mid] < target) {
                low = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr = {-1, 0, 3, 5, 9, 12};
        Solution704 solution704 = new Solution704();
        System.out.println(solution704.search(arr, 13));
    }

}
